/**
 * 费用配置
 * */


(function () {
})();


//列表
function getList(){
    $.ajax({
        type: apis.eqCostList.method,
        url: apis.eqCostList.url,
        data: {},
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg}); return
            }
            var d = res.data;
            var h = '', i;
            for (i = 0; i < d.length; i ++) {
                h += '<tr class="text-c">';
                h += '<td>' + d[i].tname + '</td>';
                h += '<td>' + d[i].cost + '</td>';
                h += '<td>' + d[i].addtime + '</td>';
                h += '<td class="f-14">';
                h += '<a href="javascript:;" onclick="cost_del(' + d[i].id + ');" style="text-decoration: none; color: red;">';
                h += '删除<i class="Hui-iconfont">&#xe6e2;</i>';
                h += '</a>';
                h += '</td>';
                h += '</tr>';
            }
            $('tbody').html(h);
            $('#pageTotal').html(d.length);
            pages.total = res.total;
            pageHtml(pages);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}


//编辑
function cost_edit(title,url,id,w,h){
    url += '?id=' + id;
    layer_show(title,url,w,h);
}


//删除
function cost_del(id){
    var msg = '确认要 <b style="color: red; font-size: 20px;">删除</b> 吗？';
    layer.confirm(msg,function(index){
        $.ajax({
            type: apis.eqCostDel.method,
            url: apis.eqCostDel.url,
            data: { id: id },
            success: function (res) {
                console.log(res);
                if (res.code < 0) {
                    msgPop({msg: res.msg}); return
                }
                layer.msg('已删除!',{icon: 1,time: 1000});
                setTimeout(function(){
                    top.location.reload();
                }, 1000);
            },
            error: function () {
                console.log('错误了！');
            }
        });
    });
}


//保存更新
function add(){
    var formData = {
        type: $('#type').val(),
        cost: $('#cost').val(),
    };
    console.log(formData);
    if (!formData.type) {
        msgPop({msg: '类型必须的'}); return
    }
    if (!formData.cost) {
        msgPop({msg: '额度必须的'}); return
    }
    $.ajax({
        type: apis.eqCostAdd.method,
        url: apis.eqCostAdd.url,
        data: formData,
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg}); return
            }
            msgPop({msg: '操作成功'});
            setTimeout(function(){
                top.location.reload();
            }, 1000);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}